Skip to content

Enhancement/11092 refactor reporting key events datapoints#12391

Open
abdelmalekkkkk wants to merge 8 commits intodevelopfrom
enhancement/11092-refactor-reporting-key-events-datapoints
Open

Enhancement/11092 refactor reporting key events datapoints#12391
abdelmalekkkkk wants to merge 8 commits intodevelopfrom
enhancement/11092-refactor-reporting-key-events-datapoints

Conversation

@abdelmalekkkkk
Copy link
Copy Markdown
Collaborator

@abdelmalekkkkk abdelmalekkkkk commented Mar 26, 2026

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 26, 2026

🤖 This comment is automatically updated by CI workflows. Each section is managed independently.

📦 Build files for 5ab1bf9:

🎭 Playwright reports for 5ab1bf9:

Copy link
Copy Markdown
Collaborator

@hussain-t hussain-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @abdelmalekkkkk! Could you please resolve the conflicts with the latest develop and send it back?

@abdelmalekkkkk abdelmalekkkkk force-pushed the enhancement/11092-refactor-reporting-key-events-datapoints branch from 99e0f3f to bf546b0 Compare April 6, 2026 15:10
@abdelmalekkkkk
Copy link
Copy Markdown
Collaborator Author

@hussain-t Done! Back to you.

Copy link
Copy Markdown
Collaborator

@hussain-t hussain-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @abdelmalekkkkk! Overall, the changes look good. However, I've left a concern and a few minor comments. Please take a look.

*
* @var Analytics_4_Report_Response
*/
private $reportResponse;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use snake_case as per WP standards.

Suggested change
private $reportResponse;
private $report_response;

}
}


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the extra blank line.

Suggested change

*/
private $analytics;


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the extra blank line.

Suggested change

'service' => function () use ( $service ) {
return $service;
},
'shareable' => true,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get_Report extends Shareable_Datapoint which unconditionally returns true from is_shareable(). Passing 'shareable' => true in the definition is redundant.

Suggested change
'shareable' => true,


use Google\Site_Kit\Core\REST_API\Data_Request;
use Google\Site_Kit\Modules\Analytics_4\Datapoints\Get_Key_Events;
use Google\Site_Kit\Modules\Analytics_4\Report\Response as ReportResponse;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this unused import.

Suggested change
use Google\Site_Kit\Modules\Analytics_4\Report\Response as ReportResponse;

Comment on lines +80 to +82
use Google\Site_Kit\Modules\Analytics_4\Datapoints\Get_Report;
use Google\Site_Kit\Modules\Analytics_4\Datapoints\Get_Key_Events;
use Google\Site_Kit\Modules\Analytics_4\Datapoints\Get_Has_Property_Access;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nitpicky one, however, while we are at it, can you reorder these imports and group them with other Get_* imports?

protected function is_shared_data_request( Data_Request $data ) {
$datapoint = $this->get_datapoint_definition( "{$data->method}:{$data->datapoint}" );
$oauth_client = $this->get_oauth_client_for_datapoint( $datapoint );
$datapoint = $this->get_datapoint_definition( "{$data->method}:{$data->datapoint}" );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactored is_shared_data_request() no longer accounts for the scope validation fallback in get_oauth_client_for_datapoint().

Previously, if all sharing conditions were met but the owner's scopes failed validation, get_oauth_client_for_datapoint() would fall back to the default client, and is_shared_data_request() would return false (since the clients matched). Now it returns true regardless of scope validation.

This means shared-data restrictions (e.g. date range limits in GET:batch-report, metric/dimension validation in AdSense) could be applied to requests that are actually using the current user's own credentials — potentially restricting data the user should have full access to.

Should this method preserve the old scope-aware behavior?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out. I thought checking the clients was just a quick way to determine if the request was shared. I reverted some of the changes and only left the new is_shared_datapoint_request. Please take another look.

@abdelmalekkkkk abdelmalekkkkk force-pushed the enhancement/11092-refactor-reporting-key-events-datapoints branch 2 times, most recently from 5168e7c to 1a10f88 Compare April 7, 2026 11:42
@abdelmalekkkkk abdelmalekkkkk force-pushed the enhancement/11092-refactor-reporting-key-events-datapoints branch from 1a10f88 to 5ab1bf9 Compare April 7, 2026 11:53
@abdelmalekkkkk
Copy link
Copy Markdown
Collaborator Author

Thanks @hussain-t. I addressed all your comments. Please take another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants